Add-PSSnapin Microsoft.Sharepoint.Powershell
 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint") 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration") 
 
Write-Host "Notice: Master page file must be in the root web"

$url = Read-Host "Enter site url"
$master = Read-Host "Enter master page name with extension (seattle.master)"

if([string]::IsNullOrEmpty($url) -or [string]::IsNullOrEmpty($master)) { 
    throw [System.IO.FileNotFoundException] "Some parameters are incorrect"
}

$site = Get-SPSite -Identity $url
$web = $site.RootWeb
$destUrl = $web.Url + "/_catalogs/masterpage/" + $master
$fullUrl = New-Object System.Uri($destUrl)
$masterUri = $fullUrl.AbsolutePath.replace("%20"," ")
$file = $web.GetFile($fullUrl.AbsolutePath);

if (!$file.Exists) {
    throw [System.IO.FileNotFoundException] "File does not exist"
}

write-host "Setting master page url for:" -foregroundcolor "green"

foreach ($subweb in $site.AllWebs) {
    write-host $subweb.url
    $subweb.MasterUrl = $masterUri #"/_catalogs/masterpage/mycustom.master";
    $subweb.CustomMasterUrl = $masterUri #"/_catalogs/masterpage/mycustom.master";
    $subweb.Update();
    $websSuccess += $subweb.url
    $subweb.Dispose();
}

write-host "Master Page Url set to: " + $masterUri -foregroundcolor "green"

$web.dispose()